cmake_minimum_required(VERSION 3.10)
project(learn_linux_net)

set(CMAKE_CXX_STANDARD 17)

# Add spdlog as a subdirectory
add_subdirectory(external/spdlog)

# Create a library for the core logging functionality
add_library(giso
    src/Logger.cpp
    src/Logger.h
    src/EventLoop.cpp
    src/EventLoop.h
    src/Poller.cpp
    src/Poller.h
    src/Channel.cpp
    src/Channel.h
    src/Buffer.cpp
    src/Buffer.h
    src/TcpConnection.cpp
    src/TcpConnection.h
    src/Acceptor.cpp
    src/Acceptor.h
    src/TcpServer.cpp
    src/TcpServer.h
    src/TcpClient.cpp
    src/TcpClient.h
    src/TaskQueue.cpp
    src/TaskQueue.h
    src/ThreadPool.cpp
    src/ThreadPool.h
    src/InetAddress.cpp
    src/InetAddress.h
)

# Link the core library to spdlog
target_link_libraries(giso spdlog::spdlog -latomic)

# Add include directories
target_include_directories(giso PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}/src
    ${CMAKE_CURRENT_SOURCE_DIR}/external/spdlog/include
)

# Add executable
# Add executable for example
add_executable(test_log example/test_log.cpp)
target_link_libraries(test_log giso)
target_include_directories(test_log PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}/src
)

add_executable(test_task example/test_task.cpp)
target_link_libraries(test_task giso)
target_include_directories(test_task PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}/src
)

add_executable(test_server example/test_server.cpp)
target_link_libraries(test_server giso)
target_include_directories(test_server PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}/src
)

add_executable(test_client example/test_client.cpp)
target_link_libraries(test_client giso)
target_include_directories(test_client PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}/src
)

add_executable(echo_server example/echo_server.cpp)
target_link_libraries(echo_server giso)
target_include_directories(echo_server PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}/src
)

add_executable(test_long_msg example/test_long_msg.cpp)
target_link_libraries(test_long_msg giso)
target_include_directories(test_long_msg PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}/src
)

add_executable(native_echo_server example/native_echo_server.cpp)

# target_link_libraries(simpleserver giso)
# target_include_directories(simpleserver PUBLIC
#     ${CMAKE_CURRENT_SOURCE_DIR}/src
# )

# # Add executable for simple client
# add_executable(simpleclient ${CMAKE_CURRENT_SOURCE_DIR}/example/simpleclient.cpp)
# target_link_libraries(simpleclient giso)
# target_include_directories(simpleclient PUBLIC
#     ${CMAKE_CURRENT_SOURCE_DIR}/src
# )

set(EXPORT_COMPILE_COMMANDS ON)